type StorageValue = string | number | boolean | object | null;
const saveStorage = <T extends StorageValue>(k: string, v: T) => {
    if (typeof v === 'string') {
        localStorage.setItem(k, v)
    } else {
        const s = JSON.stringify(v)
        localStorage.setItem(k, s)
    }
}
const getStorage = <T extends StorageValue>(k: string): T => {
    const v = localStorage.getItem(k)
    if (typeof v === 'string') {
        return v as T
    } else {
        return JSON.stringify(v) as T
    }


}
const clerStorage = () => {
    localStorage.clear()
}
const deleteStorage = (k: string): void => {
    localStorage.delete()
}
export {
    saveStorage,
    getStorage,
    clerStorage,
    deleteStorage
}